#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>

#define UNIXSTR_PATH "/tmp/unix_stream.sock"

int main(void)
{

    int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
    if (sockfd == -1)
    {
        perror("socket error:　");
        exit(EXIT_FAILURE);
    }

   


    struct sockaddr_un serverAddr;
    int addrLen = sizeof(serverAddr);
    memset(&serverAddr, 0, addrLen);
    serverAddr.sun_family = AF_LOCAL;
    strcpy(serverAddr.sun_path, UNIXSTR_PATH);

    if (connect(sockfd, (struct sockaddr *)&serverAddr, addrLen) < 0)
    {
        perror("connect error: ");
        exit(EXIT_FAILURE);
    }

    char *str = "Hello World";

    write(sockfd, str, strlen(str));

    char buf[1024] = {0};
    read(sockfd, buf, 1024);

    printf("%s\n", buf);

    return 0;
}